from fastapi import FastAPI, WebSocket, WebSocketDisconnect, BackgroundTasks
from langchain_openai import ChatOpenAI
from langchain.agents import create_openai_tools_agent, AgentExecutor, tool
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain.schema import StrOutputParser
from langchain.memory import ConversationTokenBufferMemory
from langchain_community.chat_message_histories import RedisChatMessageHistory
from langchain_community.document_loaders import WebBaseLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
import os
import asyncio
import uuid

os.environ["LANGCHAIN_TRACING_V2"]="false"
os.environ["LANGCHAIN_API_KEY"]="ls__a339aed7ea934ec999736421cdb43629"
os.environ["LANGCHAIN_PROJECT"]="samibot"

os.environ["OPENAI_API_KEY"] = "sk-83S6JB0eSdH536lC9aD1F16482C04dC69c02Ba6571B5A0Fb"
os.environ["OPENAI_API_BASE"] = "https://ai-yyds.com/v1"

os.environ["SERPAPI_API_KEY"] = "e7b15718df583476214651b32a4e835523f3bac273d511341a1de30430b2164e"
REDIS_URL = "redis://:@127.0.0.1:16379" #os.getenv("REDIS_URL")

app = FastAPI()

chatmodel = ChatOpenAI(
            # model = "gpt-4o-mini",
            model="gpt-3.5-turbo",
            # model="gpt-4-turbo-preview",
            temperature=0,
            streaming=True,
        )
